<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>主界面</title>
    <!--引入elementui得样式-->
    <link type="text/css" rel="stylesheet" href="/css/index.css"/>
    <!--引入vue得依赖必须再elementui之前引入vue-->
    <script type="text/javascript" src="/js/vue.js"></script>
    <script type="text/javascript" src="/js/index.js"></script>
    <script type="text/javascript" src="/js/axios.min.js"></script>
    <script type="text/javascript" src="/js/qs.min.js"></script>
</head>
<body>
<div id="app">
    <el-container style="height: 100%">
        <el-header>Header</el-header>
        <el-container>
            <el-aside width="200px">
                <el-menu
                        default-active="2"
                        class="el-menu-vertical-demo"
                        @open="handleOpen"
                        @close="handleClose"
                        background-color="#545c64"
                        text-color="#fff"
                        active-text-color="#ffd04b">
                        <el-submenu :index="menu.id" v-for="menu in leftMenu">
                            <template slot="title">{{menu.name}}</template>
                            <el-menu-item :index="child.id" v-for="child in menu.children">
                                <a style="color: white;text-decoration: none"    @click="showContent(child.url,child.name)">{{child.name}}</a>
                            </el-menu-item>
                        </el-submenu>
                </el-menu>
            </el-aside>
            <el-main>
                <!--标签页-->
                <el-tabs v-model="editableTabsValue" type="card" closable @tab-remove="removeTab">
                    <el-tab-pane
                            v-for="(item, index) in editableTabs"
                            :key="item.name"
                            :label="item.title"
                            :name="item.name"
                    >
                        <!--   {{item.content}}-->
                        <iframe :src="item.url"  frameborder="0" width="100%" height="100%;"></iframe>
                    </el-tab-pane>
                </el-tabs>
            </el-main>
        </el-container>
        <el-footer>Footer</el-footer>
    </el-container>
</div>
</body>
<script>
      var app=new Vue({
           el:"#app",
           data:{
                //左侧菜单
                leftMenu:[],
               //标签页 开始
               editableTabsValue: '1',
               editableTabs: [{
                   title: '首页',
                   name: '1',
                   url: '/home.jsp'
                   //content: 'Tab 1 content'
               }],
               tabIndex: 1
           },
           created(){
                this.initLeftMenu();
           },
           methods:{
                initLeftMenu(){
                     axios.get("/permission/leftPermission").then(resp=>{
                          this.leftMenu=resp.data.data;
                     })
                },
               //显示当前连接的内容
               showContent(url,menuName){
                   //alert(url+","+menuName);
                   //直接调用添加页签页
                   this.addTab(menuName,url);
               },
               //添加标签页
               addTab(targetName,url) { //targetName 页签页名称   url 对应的地址
                   let newTabName = ++this.tabIndex + '';
                   //获取所有的标签页
                   let tabs = this.editableTabs;
                   //定义是否已经标签变量
                   var  isHaveTab = false;
                   //循环所有页签页 判断当前点击标签页名称已经存在
                   tabs.forEach((tab, index) => {
                       //如果为true 说明当前点击节点（部门管理），已经存在标签页
                       if(targetName === tab.title){// 判断是否相等  1=='1' 值相等  true   1==='1'  false 类型和值都香港等
                           isHaveTab = true;
                           newTabName =tab.name;
                       }
                   });
                   //如果不存在 添加一个
                   if(!isHaveTab) {
                       this.editableTabs.push({
                           title: targetName,
                           name: newTabName,
                           url: url
                           //content: 'New Tab content'
                       });
                   }
                   //如果存在，直接让高亮
                   this.editableTabsValue = newTabName;
               },
               //移除页签页
               removeTab(targetName) {
                   let tabs = this.editableTabs;
                   let activeName = this.editableTabsValue;
                   if (activeName === targetName) {
                       tabs.forEach((tab, index) => {
                           if (tab.name === targetName) {
                               let nextTab = tabs[index + 1] || tabs[index - 1];
                               if (nextTab) {
                                   activeName = nextTab.name;
                               }
                           }
                       });
                   }

                   this.editableTabsValue = activeName;
                   this.editableTabs = tabs.filter(tab => tab.name !== targetName);
               },
           }
      })
</script>
<style>
    html,body,#app{
        margin: 0px;
        padding: 0px;
        height: 100%;
    }
    .avatar-uploader .el-upload {
        border: 1px dashed #d9d9d9;
        border-radius: 6px;
        cursor: pointer;
        position: relative;
        overflow: hidden;
    }
    .avatar-uploader .el-upload:hover {
        border-color: #409EFF;
    }
    .avatar-uploader-icon {
        font-size: 28px;
        color: #8c939d;
        width: 178px;
        height: 178px;
        line-height: 178px;
        text-align: center;
    }
    .avatar {
        width: 178px;
        height: 178px;
        display: block;
    }
    .el-header, .el-footer {
        background-color: #B3C0D1;
        color: #333;
    }

    .el-aside {
        background-color: #545c64;
        color: #333;
        height: 100%;
    }

    .el-main {
        background-color: #E9EEF3;
        color: #333;
        height: 100%;
    }

    body > .el-container {
        height: 100%;
    }

</style>
</html>
